/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaIngrediente.java
 *
 * Created on 06/04/2011, 01:04:53 AM
 */

package vistas;

import controladores.ControladorIngrediente;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 *
 * @author oscar
 */
public class VistaIngrediente extends javax.swing.JFrame {

    private Vector<JTextField> textos;
    private Vector<JButton> botones;
    private ControladorIngrediente control;

    /** Creates new form VistaIngrediente */
    public VistaIngrediente() {
        initComponents();
        botones = new Vector<JButton>();
        botones.add(btnSalir);
        botones.add(btnConsultar);
        botones.add(btnGenerar);
        botones.add(btnRegistrar);
        botones.add(btnCancelar);
        botones.add(btnEliminar);
        botones.add(btnActualizar);
        textos = new Vector<JTextField>();

        textos.add(txtCodigo);
        textos.add(txtDescripcion);
        textos.add(txtCantCom);
        textos.add(txtCantidad);
        textos.add(txtPrecio);

        control= new ControladorIngrediente(this);
        btnCancelar.setActionCommand("Cancelar");
        btnConsultar.setActionCommand("Consultar");
        btnRegistrar.setActionCommand("Registrar");
        btnSalir.setActionCommand("Salir");
        btnGenerar.setActionCommand("Generar");
        btnEliminar.setActionCommand("Eliminar");
        btnActualizar.setActionCommand("Actualizar");
        for (JButton boton : botones) {
            boton.addActionListener(control);
        }
        txtCantCom.setText("0");
        cancelar();
    }

   public boolean validarVacios(){
        for (JTextField texto : textos){
            System.out.println(texto.getName());
            if(texto.getText().isEmpty())

                return false;
       }
       return true;
    }

    public boolean validarNumeros(){
        for (int i = 2; i < textos.size(); i++)
            try{
                if(Double.parseDouble(textos.elementAt(i).getText())<0)
                    return false;
            }catch(NumberFormatException ex){
                return false;
            }

        return true;
    }



     public void cancelar(){
        for (JTextField texto : textos){
            texto.setEditable(true);
            texto.setText("");
        }
        txtCodigo.setEditable(true);
        txtCantidad.setEditable(true);
        mostrar(false);
        txtCantCom.setText("0");
    }

     public void mostrar(boolean sw){
        txtCantCom.setVisible(sw);
        jLabel7.setVisible(sw);
     }

    public JTextField getTxtCantCom() {
        return txtCantCom;
    }

    public JTextField getTxtCantidad() {
        return txtCantidad;
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public JTextField getTxtDescripcion() {
        return txtDescripcion;
    }

    public JTextField getTxtPrecio() {
        return txtPrecio;
    }

    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtDescripcion = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtPrecio = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtCantidad = new javax.swing.JTextField();
        txtCantCom = new javax.swing.JTextField();
        btnGenerar = new javax.swing.JButton();
        btnRegistrar = new javax.swing.JButton();
        btnConsultar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnActualizar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Ingredientes");
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 13));
        jLabel1.setText("Descripcion:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(160, 80, 140, 32);

        txtDescripcion.setFont(new java.awt.Font("Arial", 0, 13));
        getContentPane().add(txtDescripcion);
        txtDescripcion.setBounds(280, 80, 190, 32);

        jLabel3.setFont(new java.awt.Font("Arial", 0, 13));
        jLabel3.setText("Precio:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(160, 130, 224, 32);

        txtPrecio.setFont(new java.awt.Font("Arial", 0, 13));
        getContentPane().add(txtPrecio);
        txtPrecio.setBounds(280, 130, 190, 30);

        jLabel6.setFont(new java.awt.Font("Arial", 0, 15));
        jLabel6.setText("Codigo:");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(160, 40, 60, 30);

        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });
        getContentPane().add(txtCodigo);
        txtCodigo.setBounds(280, 40, 190, 30);

        jLabel7.setFont(new java.awt.Font("Arial", 0, 13));
        jLabel7.setText("Cantidad Comprada:");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(160, 230, 118, 15);

        jLabel5.setFont(new java.awt.Font("Arial", 0, 13));
        jLabel5.setText("Cantidad:");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(160, 180, 55, 30);

        txtCantidad.setFont(new java.awt.Font("Arial", 0, 13));
        getContentPane().add(txtCantidad);
        txtCantidad.setBounds(280, 180, 190, 30);

        txtCantCom.setFont(new java.awt.Font("Arial", 0, 13)); // NOI18N
        txtCantCom.setText("0");
        getContentPane().add(txtCantCom);
        txtCantCom.setBounds(280, 220, 190, 30);

        btnGenerar.setFont(new java.awt.Font("Arial", 1, 15));
        btnGenerar.setText("Generar");
        getContentPane().add(btnGenerar);
        btnGenerar.setBounds(480, 60, 120, 30);

        btnRegistrar.setFont(new java.awt.Font("Arial", 1, 15));
        btnRegistrar.setText("Registrar");
        btnRegistrar.setPreferredSize(new java.awt.Dimension(80, 30));
        getContentPane().add(btnRegistrar);
        btnRegistrar.setBounds(10, 280, 120, 30);

        btnConsultar.setFont(new java.awt.Font("Arial", 1, 15));
        btnConsultar.setText("Consultar");
        getContentPane().add(btnConsultar);
        btnConsultar.setBounds(480, 30, 120, 30);

        btnEliminar.setFont(new java.awt.Font("Arial", 1, 15));
        btnEliminar.setText("Eliminar");
        btnEliminar.setPreferredSize(new java.awt.Dimension(80, 30));
        getContentPane().add(btnEliminar);
        btnEliminar.setBounds(270, 280, 120, 30);

        btnSalir.setFont(new java.awt.Font("Arial", 1, 15));
        btnSalir.setText("Salir");
        getContentPane().add(btnSalir);
        btnSalir.setBounds(530, 280, 120, 30);

        btnCancelar.setFont(new java.awt.Font("Arial", 1, 15));
        btnCancelar.setText("Cancelar");
        btnCancelar.setPreferredSize(new java.awt.Dimension(80, 30));
        getContentPane().add(btnCancelar);
        btnCancelar.setBounds(400, 280, 120, 30);

        btnActualizar.setFont(new java.awt.Font("Arial", 1, 15));
        btnActualizar.setText("Actualizar");
        getContentPane().add(btnActualizar);
        btnActualizar.setBounds(140, 280, 120, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-660)/2, (screenSize.height-370)/2, 660, 370);
    }// </editor-fold>//GEN-END:initComponents

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtCodigoActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaIngrediente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGenerar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JTextField txtCantCom;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtPrecio;
    // End of variables declaration//GEN-END:variables

}
